/**   
*    
* @file
* @brief
* @文件名	: CommonWrapContentGridView
* @版权所有	: 网龙应用软件开发一部
* @作  者	: chenqian
* @创建时间	: 2014-8-6 上午11:12:21 
* @文件描述	:  
* @version	Ver 1.1
*/
package com.common.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

/**
 * 单纯的GridView的高度可以wrapcontent的控件 
 * <br>Created 2014-8-6 上午11:12:21
 * @version  1.3
 * @author   chenqian		
 *
 * @see 	 
 */

public class CommonWrapContentGridView extends GridView{
	/**
	 * CommonWrapContentGridView的构造函数
	 * Creates a new instance of WrapContentGridView.
	 * <br>Created 2014-6-5 下午1:48:01
	 * @param context 上下文
	 */
	public CommonWrapContentGridView(Context context) {
		super(context);
	}

	/**
	 * CommonWrapContentGridView的构造函数
	 * Creates a new instance of WrapContentGridView.
	 * <br>Created 2014-6-5 下午1:48:32
	 * @param context 上下文
	 * @param attrs attrs
	 */
	public CommonWrapContentGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	/**
	 * CommonWrapContentGridView的构造函数
	 * Creates a new instance of WrapContentGridView.
	 * <br>Created 2014-6-5 下午1:48:56
	 * @param context 上下文
	 * @param attrs attrs
	 * @param defStyle defStyle
	 */
	public CommonWrapContentGridView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int heightSpec;

		if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
			// The great Android "hackatlon", the love, the magic.
			// The two leftmost bits in the height measure spec have
			// a special meaning, hence we can't use them to describe height.
			heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
					MeasureSpec.AT_MOST);
		} else {
			// Any other height should be respected as is.
			heightSpec = heightMeasureSpec;
		}

		int widthSpec = widthMeasureSpec;
		super.onMeasure(widthSpec, heightSpec);
	}
}
